package cn.sciento.boot.api.customize.config;

import cn.sciento.boot.api.customize.service.ApiCustomizeService;
import cn.sciento.core.message.MessageAccessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

public class CustomizeInitializeConfig implements InitializingBean {
  private static final Logger LOGGER = LoggerFactory.getLogger(CustomizeInitializeConfig.class);
  
  @Value("${spring.application.name}")
  private String applicationName;
  
  @Autowired
  private ApiCustomizeService apiCustomizeService;
  
  public void afterPropertiesSet() {
    try {
      LOGGER.info("apply customize rule init ...");
      this.apiCustomizeService.customize(this.applicationName);
    } catch (Exception e) {
      LOGGER.warn("apply customize rule error,", e);
    } 
    MessageAccessor.addBasenames(new String[] { "classpath:messages/messages_customize" });
  }
}
